package userdisplays;

import java.io.Serializable;

import users.User;

import networkedmodules.Module;
import networkedmodules.ModuleGroup;
import networkedmodules.Update;

public class NewPanelUpdate extends Update implements Serializable
{
	private static final long serialVersionUID = 1L;
	User user;
	UserPanel panel;
	
	public NewPanelUpdate(User user, UserPanel panel)
	{
		setKey(panel.display.getKey());
		this.user = user;
		this.panel = panel;
	}
	
	public void performUpdate(Module module)
	{
		UserPanelGroup group = (UserPanelGroup)module;
		group.putPanel(user, panel);
		if(module.getModuleGroup().getType() == ModuleGroup.HOST)
		{
		    for(User u : group.panels.keySet())
		        group.getModuleGroup().sendUpdate(new UserPanelUpdate(u, (UserPanel)group.panels.get(u).getComponent(0)));
		}
	}

	public String toString()
	{
		return "New panel: " + user + ": " + panel;
	}
}
